package com.woniuxy.services.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.daos.UsersDao;
import com.woniuxy.entitys.Users;
import com.woniuxy.services.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.SQLIntegrityConstraintViolationException;
import java.util.List;

@Service
@Transactional
public class UserServiceImpl implements UserService {


    @Autowired
    private UsersDao usersDao;

    //    根据电话和密码登录
    @Override
    public Users login(String user_tel, String user_password) {
        //System.out.println("in IPML *************");
        return usersDao.login(user_tel, user_password);
    }


    @Override
    public Users selusernamebyusercode(String sale_creatcode) {
        return usersDao.seluserbyusercode(sale_creatcode);
    }

    // 根据user_id查询员工
    @Override
    public Users getUserByUid(Integer user_id) {
        return usersDao.selectByPrimaryKey(user_id);
    }

    //查询全部员工
    @Override
    public List<Users> getAllUsers() {
        return usersDao.selectAllUsers();
    }

    @Override
    public List<Users> getUsersByRole_id() {
        return usersDao.selectUsersByRole_id();
    }


    //修改某个用户
    @Override
    public Integer updUser(Users users) {
        return usersDao.updateByPrimaryKeySelective(users);
    }

    //保存添加员工
    @Override
    public Integer addUser(Users users)   {



        return usersDao.insertSelective(users);

    }


    //批量删除（修改）员工
    @Override
    public Integer updSomeUsers(Object[] checkedIds) {
        return usersDao.updateByIds(checkedIds);
    }


    //通过查询语句查询员工
    @Override
    public PageInfo<Users> getUsersByKey(Integer currentPage, Integer pageSize, String key, String value) {
        PageHelper.startPage(currentPage, pageSize);
        List<Users> users = usersDao.getUsersByKey(key, value);
        PageInfo<Users> pageInfo = new PageInfo<Users>(users);

        return pageInfo;
    }

    @Override
    public List<Users> getAllWorkUser() {
        return usersDao.getAllWorkUser();
    }

    //查询所有客户经理的id和name
    @Override
    public List<Users> getAllManager() {
        return usersDao.getAllManager();
    }
}
